import { robotMsg, sendWeComMsg, isWorkday, getCurrentTime } from '@/utils'
import { Injectable, Logger } from '@nestjs/common'
import { Cron } from '@nestjs/schedule'

@Injectable()
export class RobotService {
  private readonly logger = new Logger(RobotService.name)

  @Cron('30 16 * * *', { timeZone: 'Asia/Shanghai' })
  async sendDinnerReminder() {
    try {
      const date = getCurrentTime('YYYY-MM-DD')
      const flag = await isWorkday(date)
      if (!flag) {
        this.logger.log(`今日${date}为节假日/周末，无需发送晚餐提醒`)
        return
      }
      // BeiShangKaoTuDou
      await sendWeComMsg('可以点晚餐了🍱https://orderfood.tears.asia/home')
      this.logger.log('工作日晚餐提醒发送成功')
    } catch (error) {
      this.logger.error('晚餐提醒发送失败', error.stack)
    }
  }

  // 每天早上8:00签到提醒（不区分节假日）
  @Cron('0 8 * * *', { timeZone: 'Asia/Shanghai' })
  async sendSignInReminder() {
    try {
      const date = getCurrentTime('YYYY-MM-DD')
      const content = `【签到提醒】📅
早上好，今日签到还没完成喔！
立即签到：https://orderfood.tears.asia/home`

      await sendWeComMsg(content)
      this.logger.log(`[${date}]签到提醒发送成功`)
    } catch (error) {
      this.logger.error('签到提醒发送失败', error.stack)
    }
  }
}
